package com.ruoyi.modularbusiness.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.modularbusiness.domain.Formbody;
import com.ruoyi.modularbusiness.service.IFormbodyService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 表单内容Controller
 * 
 * @author 刘振
 * @date 2023-01-05
 */
@RestController
@RequestMapping("/formbody")
public class FormbodyController extends BaseController
{
    @Autowired
    private IFormbodyService formbodyService;

    /**
     * 查询表单内容列表
     */
    @RequiresPermissions("modularbusiness:formbody:list")
    @GetMapping("/list")
    public TableDataInfo list(Formbody formbody)
    {
        startPage();
        List<Formbody> list = formbodyService.selectFormbodyList(formbody);
        return getDataTable(list);
    }

    /**
     * 导出表单内容列表
     */
    @RequiresPermissions("modularbusiness:formbody:export")
    @Log(title = "表单内容", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Formbody formbody)
    {
        List<Formbody> list = formbodyService.selectFormbodyList(formbody);
        ExcelUtil<Formbody> util = new ExcelUtil<Formbody>(Formbody.class);
        util.exportExcel(response, list, "表单内容数据");
    }

    /**
     * 获取表单内容详细信息
     */
    @RequiresPermissions("modularbusiness:formbody:query")
    @GetMapping(value = "/{fbid}")
    public AjaxResult getInfo(@PathVariable("fbid") Long fbid)
    {
        return success(formbodyService.selectFormbodyByFbid(fbid));
    }

    /**
     * 新增表单内容
     */
    @RequiresPermissions("modularbusiness:formbody:add")
    @Log(title = "表单内容", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Formbody formbody)
    {
        return toAjax(formbodyService.insertFormbody(formbody));
    }

    /**
     * 修改表单内容
     */
//    @RequiresPermissions("modularbusiness:formbody:edit")
    @Log(title = "表单内容", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Formbody formbody)
    {
        return toAjax(formbodyService.updateFormbody(formbody));
    }

    /**
     * 删除表单内容
     */
    @RequiresPermissions("modularbusiness:formbody:remove")
    @Log(title = "表单内容", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fbids}")
    public AjaxResult remove(@PathVariable Long[] fbids)
    {
        return toAjax(formbodyService.deleteFormbodyByFbids(fbids));
    }
}
